﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using aoprinter.Model;
using aoprinter.Draw;

namespace aoprinter.Core
{
    static class ImageOper
    {
        static public void AutoSizeLocation(this ModImage image, SizeF size)
        {
            if (image.Size.Width == ModBlock.AutoSize.Width)
            {
                image.Size = new SizeF(size.Width, image.Size.Height);
            }
            if (image.Size.Height == ModBlock.AutoSize.Height)
            {
                image.Size = new SizeF(image.Size.Width, size.Height);
            }
        }

        static public void Print(this ModImage image, Drawer drawer, PointF location)
        {
            if (image.Image == null)
            {
                return;
            }
            Image imageDraw = null;
            if (image.IfScale)
            {
                imageDraw = new Bitmap(image.Image, image.Size.ToSize());
            }
            else
            {
                imageDraw = (image.Image as Bitmap).Clone(new RectangleF(0, 0,
                   Math.Min(image.Image.Width, drawer.ChangeMillimeterToPixel(image.Size.Width)),
                   Math.Min(image.Image.Height, drawer.ChangeMillimeterToPixel(image.Size.Height))),
                    image.Image.PixelFormat);
            }
            drawer.DrawImage(imageDraw, new PointF(location.X + image.Location.X, location.Y + image.Location.Y));
        }
    }
}
